package com.czp;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import com.zc.utils.JDBCUtils;

import dao.DBPool;
import entity.Contact_person;

public class orderFormDao {
		//dao中的数据库连接对象
		private DBPool dbPool = DBPool.getInstance();
		private QueryRunner runner = new QueryRunner(dbPool.getDataSource());
		JDBCUtils jdbcUtils = new JDBCUtils();
		
		
		public Long saveContact(String contactName, String phone3, String email, String weixing) {
			String sql = "insert into contact_person (person_id,person_name,tel,e_mail,account_number) values (null,?,?,?,?)";
			Object[] params = {contactName,phone3,email,weixing};
			try {
				return jdbcUtils.addObject(sql, params);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
			
		}


		public int saveCustomer(String firstname, String lastname, String sex, String birthDay, String iDtype,
				String idcard, String phone, int person_id) {
			int i = 0;
			String sql = "insert into customer (customer_id,surname,last_name,sex,birthday,card_typeof,card_number,tel,person_id) values (null,?,?,?,?,?,?,?,?)";
			Object[] params = {firstname,lastname,sex,birthDay,iDtype,idcard,phone,person_id};
			try {
				i = runner.update(sql, params);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return i ;
		}


		public Long savePrice(String startDate, String endDate, int day_number, int night_day, double price_day,
				int buy_number, int bed_number, String sum_price, int person_id,int hotel_id) {
			String sql = "insert into price (price_id,in_date,out_date,day_number,night_number,buy_number,bed_number"
					+ ",price_day,sum_price,person_id,hotel_id) values(null,?,?,?,?,?,?,?,?,?,?)";
			Object[] params = {startDate,endDate,day_number,night_day,price_day,buy_number,bed_number,sum_price,person_id,hotel_id};
			try {
				return jdbcUtils.addObject(sql, params);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null ;
		}


		public Contact_person queryContact(String contactName) {
			Contact_person p = null;
			String sql = "select * from contact_person where person_name=?";
			try {
				p = runner.query(sql, new BeanHandler<Contact_person>(Contact_person.class), contactName);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return p;
		}


}
